package com.dc.base.utils

import android.app.Activity
import java.util.*

object ActivityManager {

    private val stack: Stack<Activity> = Stack<Activity>()

    fun addActivity(activity: Activity) {
        stack.add(activity)
    }

    fun removeActivity(activity: Activity) {
        stack.remove(activity)
    }

    fun finishActivity(cls: Class<*>) {
        for (activity in stack) {
            if (activity.javaClass == cls) {
                finishActivity(activity)
                return
            }
        }
    }

    fun finishActivity(activity: Activity) {
        activity.finish()
        stack.remove(activity)
    }

    fun finishAllActivity() {
        for (activity in stack) {
            activity.finish()
        }
        stack.clear()
    }
}